package com.lianbang.pharmacy.adapter

import android.text.SpannableString
import android.text.style.LeadingMarginSpan
import cn.ubest.mvvmcore.utils.ResourcesUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.lianbang.pharmacy.R
import com.lianbang.pharmacy.bean.AddressListBean

/**
 * Created by maoqi on 2020/12/16.
 */
class MyAddressListAdapter :
    BaseQuickAdapter<AddressListBean, BaseViewHolder>(R.layout.item_my_address_list) {

    init {
        addChildClickViewIds(R.id.btn_edit, R.id.btn_delete)
    }

    override fun convert(helper: BaseViewHolder, item: AddressListBean) {
        val address = "${item.province}${item.city}${item.district}${item.detail}"
        val spannableString = SpannableString(address)
        spannableString.setSpan(
            LeadingMarginSpan.Standard(ResourcesUtils.getDimens(R.dimen.dp_37), 0),
            0,
            spannableString.length,
            SpannableString.SPAN_INCLUSIVE_INCLUSIVE
        )
        helper.setText(R.id.tv_name, item.real_name)
            .setText(R.id.tv_phone, item.phone)
            .setText(R.id.tv_address, if (item.is_default == 1) spannableString else address)
            .setVisible(R.id.view_top, helper.layoutPosition == 0)
            .setVisible(R.id.tv_tag, item.is_default == 1)
    }

}